package YAPserver.score;

import java.util.HashMap;

import YAPserver.logic.Player;

public enum CountingAward implements Award{
	Coward("is a Coward"),
	BadWinner("got the Bad Winner Award"),
	Bunny("received the Bunny Award"), 
	Shopping("received the Shopping Award"),
	Chronos("was honoured with the Chronos Award"),
	Star("was honoured with the Star Award");
	
	private String name;
	private Score score;
	
	CountingAward(String name){
		this.name = name;
		score = new Score();
	}
	public String toString(){
		return name;
	}
	public void add(Player player){
		this.score.add(player);
	}
	public int getScore(Player player){
		return this.score.getScore(player);
	}

	@Override
	public void reset(HashMap<Integer, Player> players) {
		for(Integer id: players.keySet()){
			score.setScore(players.get(id), 0);
			
		}
	}
	
	private class Score{
		private HashMap<Player, Integer> scores= new HashMap<Player, Integer>();
		/**
		 * Adds one towards the specified award this class is linked to.
		 * @param award award to which will be scored
		 */
		private void add(Player player){
			if(scores.containsKey(player)){
				int newScore = scores.get(player);
				newScore++;
				scores.put(player, newScore);
				return;
			//this bit of code is probably no longer needed as the score is set to 0 for each player at the beginning of a game
			}else{
				int newScore = 1;
				scores.put(player, newScore);
			}
		}
		
		/**
		 * Returns the score a player with the specified award this class is linked to.
		 * @param award award of which the score is to be known
		 * @return the score of the specified award
		 */
		private int getScore(Player player){
			if(scores.containsKey(player)){
				return scores.get(player);
			}else{
				return startScore;
			}
		}
		
		private void setScore(Player player, int score){
			scores.put(player, score);
		}
	}
}
